const express = require('express')
const auth = require('../middleware/auth')
const router = express.Router()

// 获取停车位信息
router.get('/spaces', auth, (req, res) => {
  try {
    const spaces = {
      total: 320,
      occupied: 233,
      available: 87,
      reserved: 15,
      areas: [
        {
          id: 'A',
          name: 'A区停车场',
          total: 120,
          occupied: 89,
          available: 31
        },
        {
          id: 'B',
          name: 'B区停车场',
          total: 100,
          occupied: 78,
          available: 22
        },
        {
          id: 'C',
          name: 'C区停车场',
          total: 100,
          occupied: 66,
          available: 34
        }
      ],
      timestamp: new Date().toISOString()
    }
    
    res.json({
      success: true,
      data: spaces
    })
  } catch (error) {
    console.error('Get parking spaces error:', error)
    res.status(500).json({
      success: false,
      error: '获取停车位信息失败'
    })
  }
})

// 获取停车预约
router.get('/reservations', auth, (req, res) => {
  try {
    const reservations = [
      {
        id: '1',
        userId: 'user1',
        userName: '张三',
        spaceId: 'A-001',
        startTime: new Date().toISOString(),
        endTime: new Date(Date.now() + 3600000).toISOString(),
        status: 'active'
      }
    ]
    
    res.json({
      success: true,
      data: reservations,
      total: reservations.length
    })
  } catch (error) {
    console.error('Get parking reservations error:', error)
    res.status(500).json({
      success: false,
      error: '获取停车预约失败'
    })
  }
})

module.exports = router